<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use chrome\ChromePhp;
use common\Common;
use app\common\model\weixin\LibRequest;
use wechatUtil\Media;
/**
 * 微信素材管理
 * @name WeixinMaterial.php
 * @package cws
 * @category controller
 * @link http://www.chanekeji.com
 * @author jianfang
 * @version 2.0
 * @copyright CHANGE INC
 * @since 2016-08-13
 */
class  WeixinMaterial extends AdminController{
	/**
	 * 构造函数
	 */
	function __construct() {
		parent::__construct ();
		error_reporting ( E_ALL & ~ E_NOTICE & ~ E_DEPRECATED & ~ E_STRICT & ~ E_WARNING );
		$this->rightVerify(session('admin'), url("admin/Login/login"));
	}
	
	/**
	 * 素材列表页面
	 */
	function materialList(){
		$this->getSetMenu($this);
		$this->log(__CLASS__, __FUNCTION__, "素材列表页面", 1, 'view');
		return $this->fetch("WeixinMaterial/materialList/materialList");
	}
	
	/**
	 * 分页查询素材
	 */
	function pagingMedia(){
		$type = input('param.type');//image news video voice
		$pageIndex = input('param.pageIndex');
		$pageSize = input('param.pageSize');
		$offset = ($pageIndex  - 1) *  $pageSize;
		$result = Media::getMediaList($type,$offset,$pageSize);
		echo json_encode($result);
	}
	
	/**
	 * 删除素材
	 */
	function deleteMedia(){
		$mediaId = input('param.mediaId');
		$this->log(__CLASS__, __FUNCTION__, "删除素材", 0, 'del');
		echo Media::deleteMedia($mediaId);
	}
	
	/**
	 * 更新素材
	 */
	function updateNews(){
		$jsonString = input('param.news');
		$this->log(__CLASS__, __FUNCTION__, "更新素材", 0, 'edit');
		echo Media::updateNews($jsonString);
	}
	
	/**
	 * 上传图文消息内的图片获取URL
	 * 需要传入id为media的post表单
	 */
	function addNewsImage(){
		echo Media::addNewsImage();
	}
	
	/**
	 * 添加素材
	 * 需要传入id为media的post表单
	 */
	function addMedia(){
		$type = input('param.type');
		$title = input('param.title');
		$introduction = input('param.introduction');
		$this->log(__CLASS__, __FUNCTION__, "添加素材", 0, 'add');
		echo Media::addMedia($type,$title,$introduction);
	}
	
	/**
	 * 通过mediaId获取素材内容
	 */
	function getMedia(){
		$mediaId = input('param.mediaId');
		echo Media::getMedia($mediaId);
	}
	
}